package com.qingyue.day01;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Locale;

public class TestMain {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

		// 生成一个BeanDefinition对象，并设置beanClass为User.class，并注册到ApplicationContext中
		AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
		beanDefinition.setBeanClass(User.class);
		//beanDefinition.setScope("prototype"); // 设置作用域
		beanDefinition.setInitMethodName("init"); // 设置初始化方法
		context.registerBeanDefinition("user", beanDefinition);

		System.out.println(context.getBean("user"));
		System.out.println(context.getBean("user"));

		System.out.println(context.getMessage("test", null, "default", new Locale("en", "EN")));
	}
}
